// pages/person/personIndex.js
const app = getApp()
Page({
  
  /**
   * 页面的初始数据
   */

  data: {
    user: '', //缓存的用户数据
    uservip: '', //接口的用户数据
    myorder: [{
        id: 1,
        name: '待付款',
        url: '/pages/imgs/img/waitpay.png'
      },
      {
        id: 2,
        name: '待发货',
        url: '/pages/imgs/img/pay.png'
      },
      {
        id: 3,
        name: '待收货',
        url: '/pages/imgs/img/waitsend.png'
      },
      {
        id: 4,
        name: '待评价',
        url: '/pages/imgs/img/waitspeak.png'
      },
      // { id: 4, name: '售后', url: '/pages/imgs/img/aftersales.png' },
    ],
    yaoqing: {
      id: 0,
      name: '邀请好友',
      url: '/pages/imgs/img/invitation.png',
      jumpurl: '/pages/person/invite/invite'
    },
    other: [{
        id: 0,
        name: '客服中心',
        url: '/pages/imgs/img/help.png',
        jumpurl: '/pages/person/help/help'

      },
      // {
      //   id: 0,
      //   name: '我的库存',
      //   url: '/pages/imgs/img/inventory.png',
      //   jumpurl: '/pages/person/warehouse/warehouse'
      // },
      {
        id: 0,
        name: '个人设置',
        url: '/pages/imgs/img/Setup.png',
        jumpurl: '/pages/person/persondetail/persondetail'
      }
      // {
      //   id: 0,
      //   name: '我的审批',
      //   url: '/pages/imgs/img/shenpi.png',
      //   jumpurl: '/pages/person/shipments/shipments'
      // },
      // {
      //   id: 0,
      //   name: '分销成员',
      //   url: '/pages/imgs/img/fenxiao.png',
      //   jumpurl: '/pages/person/fenxiao/fenxiao'
      // }
    ],
    gifts: [],
    levelhedden: 0
  },


  jumpother1: function() {
    let url = '/pages/person/fenxiao/fenxiao';
    wx.navigateTo({
      url: url,
    })
  },
  /**
   * 生命周期函数--监听页面显示
   */
  onShow: function(options) {


    this.getuserinfo()
    this.getlevel()
    let that = this



  },

  /**
   * 
   * 获取个人信息getuserinfo
   */
  getuserinfo: function() {
    let that = this;
    wx.getStorage({
      key: 'userinfo',
      success: function(res) {
        that.setData({
          user: res.data
        })
        wx.request({
          url: app.globalData.api + "getuserinfo",
          data: {
            uid: res.data.id
          },
          success: function(res2) {
            console.log('个人信息', res2, res2.data.list)
            that.setData({
              uservip: res2.data,
              userlevel: res2.data.list
            })
            let userlevel = that.data.userlevel

            userlevel.level = res2.data.list.level
            console.log(userlevel)
            wx.setStorageSync('userinfo', userlevel)

          },
        })
      },
      fail: function(res) {
        wx.showModal({
          title: '提示',
          content: '需授权后才购买',
          confirmColor: '#5FA15F',
          // showCancel: false,
          confirmText: '前往授权',
          success(res) {
            if (res.confirm) {
              wx.navigateTo({
                url: '/pages/login/welcome',
              })
            } else if (res.cancel) {

            }


          }
        })
      }
    })
  },

  /**
   * 
   * 获取会员礼包getlevel
   */
  getlevel: function() {
    let that = this;
    wx.getStorage({
      key: 'userinfo',
      success: function(res) {
        that.setData({
          user: res.data
        })
        wx.request({
          url: app.globalData.api + "getlevel",
          data: {
            uid: res.data.id
          },
          success: function(res) {
            console.log('会员礼包', res)

            that.setData({
              gifts: res.data.list
            })
          },
        })
      },
    })
  },

  /**
   * 
   * 进入购买礼包界面
   */
  intoGift: function(e) {
    let levelid = e.currentTarget.dataset.id;
    let level = e.currentTarget.dataset.level;
    let title = e.currentTarget.dataset.title;
    let price = e.currentTarget.dataset.price;
    wx.navigateTo({
      url: '/pages/person/purchaseLevel/purchaseLevel?levelid=' + levelid + '&level=' + level + '&title=' + title + '&price=' + price,
    })
  },


  // 跳订单
  jumporder: function(e) {
    let id = e.currentTarget.dataset.id;
    wx.navigateTo({
      url: '/pages/order/order?id=' + id,
    })
  },


  // 跳底部4个分类
  jumpother: function(e) {
    let url = e.currentTarget.dataset.url;
    wx.navigateTo({
      url: url,
    })
  },


  //跳钱包
  jumpwallet() {
    wx.navigateTo({
      url: '/pages/person/wallet/wallet',
    })
  },


  //跳收益
  jumpearnings() {
    wx.navigateTo({
      url: '/pages/person/earnings/earnings',
    })
  },



  // 平台收益
  Platform: function() {
    wx.navigateTo({
      url: '/pages/person/PlatformEarnings/PlatformEarnings',
    })
  },

  /**
   * 跳宝币
   */
  jumpcurrency() {
    wx.navigateTo({
      url: '/pages/person/currency/currency',
    })
  },
  /**
   * 跳团队
   */
  // 团队收益
  // 跳转
  jumpteam(e) {
    let price = e.currentTarget.dataset.price;
    // wx.navigateTo({
    //   url: '/pages/person/team/team?price=' + price,
    // })
    // },
    wx.navigateTo({
      url: '/pages/person/teamDetail/teamDetail',
    })
  },

  // 升级
  upgrade() {
    let that = this
    wx.request({
      url: app.globalData.api + "userup",
      data: {
        uid: that.data.user.id
      },
      success: function(res) {
        console.log('升级', res)
        wx.showToast({
          title: res.data.msg,
        })
        that.onLoad()
      },
    })
  },

  /**
   * 生命周期函数--监听页面加载
   */
  onLoad: function(options) {

  },

  /**
   * 生命周期函数--监听页面初次渲染完成
   */
  onReady: function() {

  },


  /**
   * 生命周期函数--监听页面隐藏
   */
  onHide: function() {

  },

  /**
   * 生命周期函数--监听页面卸载
   */
  onUnload: function() {

  },

  /**
   * 页面相关事件处理函数--监听用户下拉动作
   */
  onPullDownRefresh: function() {

  },

  /**
   * 页面上拉触底事件的处理函数
   */
  onReachBottom: function() {

  },

  /**
   * 用户点击右上角分享
   */
  onShareAppMessage: function() {

  }
})